/**
 * Created by yongwang on 2015/9/1.
 * 辅助的全局空间
 */
var gObj = {//全局命名空间
    logout: function (){//退出平台
        sessionStorage.setItem("isAuthenticated","false");
        $("#user_message").css("display","none");
        $("#left_nav").css("display","none");
        $("#right_content").css("width","100%");
        location.href = "/#/login";
    }

};

var deleteObjNull = function(data){
    for(var i in data){
        //if(data.hasOwnProperty(i)){
            if(data[i] == null)delete data[i];
        //}
    }
    return data;
};


var QuestionCategory = {
    question: '邻里问问',
    share: '随便说说',
    essence: '66精选'
};


var GetCategoryName = function(array,type) {
    if(JSON.stringify(array) != "{}") {
        array.forEach(function(temp) {
            temp.categoryName = QuestionCategory[temp.category];

            if(type && type=='image' && temp.images){
                temp.images.forEach(function(image){
                    image.imageURL = 'http://'+ imgHost+image.imageURL;
                });

                if(temp.shareImage){
                    temp.shareImage = 'http://'+ imgHost + temp.shareImage
                }
            };
        });
    }
    return array;
};

//根据参数名获取url参数值
function getQueryString(url, name) {
    var reg = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)", "i");
    var r = url.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

//获取url所有参数
function getQueryParames(url){
    var pattern = /(\w+)=(\w+)/ig;//定义正则表达式
    var parames = {};
    url.replace(pattern, function(a, b, c){parames[b] = c;});
    return parames;//返回这个数组.
}